/**************************************************************************//**
 * @item     CosyOS-III Kernel
 * @file     os_var.h
 * @brief    系统全局变量声明
 * @author   迟凯峰
 * @version  V1.2.1
 * @date     2025.04.15
 ******************************************************************************/

#ifndef __OS_VAR_H
#define __OS_VAR_H
#include "os_redef.h"

/* The Soft-RTC */
#if SYSCFG_SOFTRTC == __ENABLED__
extern  const     s_u8_t             _CONST_MEM_   s_month0day[13];
extern            s_u8_t               _RTC_MEM_   s_month2day;
extern  volatile  s_every_ts           _SYS_MEM_   s_sign_every;
extern            s_rtc_ts             _RTC_MEM_   s_rtc;
#if SYSCFG_GETRTC_INT == __ENABLED__
extern            s_rtc_ts             _RTC_MEM_   s_rtc_copy;
extern  volatile  m_bit_t            /*_SYS_MEM_*/ s_sign_rtc;
#endif
#endif
/* The Task */
extern  volatile  s_schesign_tu        _SYS_MEM_   s_sign_schedule;
extern  volatile  m_bit_t            /*_SYS_MEM_*/ s_sign_ready_delay;
extern            s_u8_t               _SYS_MEM_   s_schedulelock_counter;
extern            s_ecode_t            _SYS_MEM_   s_startup_code;
extern            s_u8_t               _SYS_MEM_   s_task_status0;
extern            s_taskhand_tsp       _SYS_MEM_   s_task_starter;
extern            s_tasknode_tsp       _SYS_MEM_   s_task_current;
extern            s_tasknode_tsp       _SYS_MEM_   s_list_timer;
#if SYSCFG_SAMEPRISCHEDULE == __TIMESHARING__
#if SYSCFG_TIMESHARINGMODE == 2
extern  const     s_sharing_t        _CONST_MEM_   s_time_sharing[SYSCFG_TASKPRIORITY];
#endif
#endif
#if SYSCFG_KERNELLOCKNESTING == __ENABLED__
extern            s_u8_t               _SYS_MEM_   s_kernellock_counter;
#endif
/* The Safe runtime */
#if SYSCFG_SAFERUNTIME == __ENABLED__
extern  volatile  m_bit_t            /*_SYS_MEM_*/ s_sign_timeout;
extern            s_tasknode_tsp       _SYS_MEM_   s_list_timeout;
#endif
/* The Timing Interrupt */
#if OS_TIMINTTOTAL
extern            s_timinthand_tsp                 s_timint_handle[OS_TIMINTTOTAL];
#endif
/* The Timing Query */
#if OS_TIMQRYTOTAL
extern            s_timqryhand_tsp                 s_timqry_handle[OS_TIMQRYTOTAL];
#endif
/* The Global Variable Accessor */
extern  volatile  m_bit_t            /*_SYS_MEM_*/ s_sign_updatecopy;
/* The Debug Interface */
#if SYSCFG_DEBUGGING == __ENABLED__
extern  volatile  m_bit_t            /*_SYS_MEM_*/ s_sign_taskmgr;
extern  volatile  m_bit_t            /*_SYS_MEM_*/ s_sign_debugsend;
extern  volatile  s_u8_t               _SYS_MEM_   s_debug_sendtype;/*
extern            char               _XDATA_MEM_   s_cmdline_sendbuff[OS_CMDLINESENDBUFFSIZE];
#if SYSCFG_DEBUG_SENDLEN == __ENABLED__
extern            size_t             _XDATA_MEM_   s_cmdline_sendlen;
#endif*/
extern            char               _XDATA_MEM_   s_taskmgr_sendbuff[OS_TASKMGRSENDBUFFSIZE];
#if SYSCFG_DEBUG_SENDLEN == __ENABLED__
extern            size_t             _XDATA_MEM_   s_taskmgr_sendlen;
#endif
extern            s_alarm_ts         _DEBUG_MEM_   s_alarm;
extern            s_fault_ts         _DEBUG_MEM_   s_fault;
#if SYSCFG_SYSTICKTIME_COUNT == __ENABLED__
extern            s_u32_t            _DEBUG_MEM_   s_tick_count1;
extern            s_u32_t            _DEBUG_MEM_   s_tick_count2;
#endif
#if SYSCFG_TASKPC_MONITOR == __ENABLED__
extern            m_pc_t               _SYS_MEM_   s_pc;
#endif
#if SYSCFG_RUNTIME_COUNT == __ENABLED__
extern            s_runtime_ts       _DEBUG_MEM_   s_runtime;
#endif
#endif
/* The Task bitmap */
extern  const s_u8_t _CONST_MEM_ s_task_map_mask[8];
extern  const s_u8_t _CONST_MEM_ s_task_map_pick[SYSCFG_TASKPICKBITMAP * 128];
#if SYSCFG_TASKPRIORITY > 64
extern  s_u8_t _SYS_MEM_ s_task_table_index;
extern  s_u8_t _SYS_MEM_ s_task_bytes_index[SYSCFG_TASKPRIORITY / 64 + !!(SYSCFG_TASKPRIORITY % 64)];
extern  s_u8_t _SYS_MEM_ s_task_ready_table[SYSCFG_TASKPRIORITY / 64 + !!(SYSCFG_TASKPRIORITY % 64)][8];
#elif SYSCFG_TASKPRIORITY > 8
extern  s_u8_t _SYS_MEM_ s_task_bytes_index;
extern  s_u8_t _SYS_MEM_ s_task_ready_table[SYSCFG_TASKPRIORITY / 8 + !!(SYSCFG_TASKPRIORITY % 8)];
#else
extern  s_u8_t _SYS_MEM_ s_task_ready_table;
#endif
extern  s_tasknode_tsp _QUE_MEM_ s_task_queue[SYSCFG_TASKPRIORITY];
extern  s_tqcount_t    _QUE_MEM_ s_task_queue_count;
#if SYSCFG_SAMEPRISCHEDULE
extern  s_u8_t         _QUE_MEM_ s_task_ready_count[SYSCFG_TASKPRIORITY];
#elif SYSCFG_MUTEX == __ENABLED__
extern  s_u8_t _SYS_MEM_ s_taskpri_ceiling;
#endif

extern  void (_CODE_MEM_ * const _CONST_MEM_ sPendSV_FIFOHandler[OS_SVID_END])(void _STATIC_MEM_ *sv);

#endif
